/*
 * swapTest1.c
 *
 *  Created on: May 28, 2013
 *      Author: koldar
 */

#include <stdio.h>
#include <stdlib.h>
#include "solution.h"
#include "tabooState.h"
#include "los.h"
#include "swap.h"
#include "parser.h"
#include "graphbmp-tools.h"

/* caso di test dello swap. ecco casi interessanti:
 * per TQ_OK T=80 Q=80
 * per Q appena sufficiente per tutti: Q=50
 * per T appena sufficiente: T=54
 * per Q appena sufficiente solo per un camion Q=45
 *
 *
 */

/* casi di test per i metodi in getCrossedEdge:
 * 3 massimi:
 * 	1-2=2-3=1-3=10
 * 	1-4=12
 * 	2-4=3-4=2
 * 4 massimi:
 *
 */


int main(int argn, const char** args){
	FILE* graphFile;
		Pgraph pgraph;
		Psolution psolution;
		PtabooState ptaboostate;
		int N;
		int K;

		PedgeID _12=initEdgeID(0,1);
		validateEdgeID(_12);
		PedgeID _13=initEdgeID(0,2);
		validateEdgeID(_13);
		PedgeID _14=initEdgeID(0,3);
		validateEdgeID(_14);
		PedgeID _23=initEdgeID(1,2);
		validateEdgeID(_23);
		PedgeID _24=initEdgeID(1,3);
		validateEdgeID(_24);
		PedgeID _34=initEdgeID(2,3);
		validateEdgeID(_34);

		if (argn==3){
			graphFile = fopen(args[1],"r");
			K = atoi(args[2]);
		}else{
			printf("numero di parametri passati errati.\n");
			return EXIT_FAILURE;
		}
		pgraph=parseGraph(graphFile,&N);
		dijkstraFiller(pgraph);
		initSmartWeights(pgraph);
		psolution=initSolution(&K,&N);
		ptaboostate=initTabooState(&N,&K,0);

		int k=0;
		addEdgeOp(_12,getEdgeGraph(pgraph,_12),psolution->states[k],psolution->gMatrix,k,ptaboostate->tls[k],0,0,true);
		addEdgeOp(_23,getEdgeGraph(pgraph,_23),psolution->states[k],psolution->gMatrix,k,ptaboostate->tls[k],0,0,true);
		addEdgeOp(_34,getEdgeGraph(pgraph,_34),psolution->states[k],psolution->gMatrix,k,ptaboostate->tls[k],0,0,true);
		addEdgeOp(_14,getEdgeGraph(pgraph,_14),psolution->states[k],psolution->gMatrix,k,ptaboostate->tls[k],0,0,true);

		drawSolutionFromScratch(
								"pictures/swapTest1_prima.bmp",
								psolution,
								pgraph->depot,
								15,
								50,
								7,
								1,
								4,
								2,
								1,
								COLOR_BLACK,
								COLOR_DARK_GREY,
								COLOR_VIOLET);

		printSolution(stdout, psolution);

		//se questo test è ancora ritenuto interessante, adattare la chiamata all'evoluzione del codice.
		// solveSwapNeighbourhood(pgraph, psolution->states[k], psolution->gMatrix, k, ptaboostate->tls[0], 1);

		drawSolutionFromScratchDefaults("pictures/swapTest1_dopo.bmp", psolution, pgraph->depot);

		printSolution(stdout, psolution);
		printf("FINE.\n");
}
